<?php

/*
 * Copyright 2015 crackerben.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace Com\Wechat\ChatService;

/**
 * 对话服务-推广支持
 */
class ExpandModel {

    /**
     * 临时二维码请求（待定）
     * @param type $token 
     */
    public function createTempTicket($token, $expire_seconds) {
        $url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=$token";
        $curl = new \Com\Wechat\CurlModel();
        $temp = array('scene' => '{"scene_id": 123}');
        $arr = array('$expire_seconds' => $expire_seconds, 'action_name' => 'QR_SCENE', 'action_info' => $temp);
        $result = json_decode($curl->curlSafePost($url, $arr));
        if (!isset($result->errcode)) {
            return $result;
        } else {
            return FALSE;
        }
    }

    /**
     * 永久二维码请求（待定）
     * @param type $token
     * @param type $expire_seconds 
     */
    public function createLimitTicket($token, $expire_seconds) {
        $url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=$token";
        $curl = new \Com\Wechat\CurlModel();
        $temp = array('scene' => '{"scene_id": 123}');
        $arr = array('action_name' => 'QR_LIMIT_SCENE', 'action_info' => $temp);
        $result = json_decode($curl->curlSafePost($url, $arr));
        if (!isset($result->errcode)) {
            return $result;
        } else {
            return FALSE;
        }
    }

    /**
     * 通过ticket换取二维码
     * @param type $ticket
     */
    public function getPicByTicket($ticket) {
        $url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=$ticket";
        $curl = new \Com\Wechat\CurlModel();
        $curl->curlFileGet($url, './Img/System/', 'erweima', 'jpg');
    }

}
